
var mapChart = echarts.init(document.getElementById("map"));
var saleBL = dataOne().saleBL;
var stockBL = dataOne().stockBL;
var saleStockR = dataOne().saleStockR;
var allMData = dataOne().allMData;

// 散点数据 和 对应经纬度
var data =[
  { name: "海门", value: 80 }
];
var geoCoordMap={
  海门: [121.15, 31.89],
};
// 获取各地区的经纬度
function convertData(){
  var res = [];
  for (var i = 0; i < data.length; i++) {
    var geoCoord = geoCoordMap[data[i].name];
    if (geoCoord) {
      res.push({
        name: data[i].name,
        value: geoCoord.concat(data[i].value)
      });
    }
  }
  return res;
}

//散点   lxxing
var base = "http://localhost:8888/bigDateApi/data/";
var findChinaData="findChinaData";
var SortSellQuantity="findSortSellQuantity";
var sortStockQuantity="sortStockQuantity"
var findChinaDataUrl = base +findChinaData;
var SortSellQuantityUrl=base+SortSellQuantity;
var sortStockQuantityUrl = base+sortStockQuantity;
findChinaDateFun()

function findChinaDateFun() {
  $.ajax({
    url: findChinaDataUrl,
    type:'POST',
    datatype: 'json',
    async: false,
    success: function (result) {
      for (let i = 0; i < result.data.sysAreas.length; i++) {
        data.push({ name: result.data.sysAreas[i].name,value:result.data.dataBookOrders[i].quantity/100})
        geoCoordMap[result.data.sysAreas[i].name]=[result.data.sysAreas[i].lng,result.data.sysAreas[i].lat]
      }
      convertData()
    }
  })
}


var Month = [
  "Jan",
  "Feb",
  "Mar",
  "Apr",
  "May",
  "Jun",
  "Jul",
  "Aug",
  "Sep",
  "Oct",
  "Nov",
  "Dec"
];

// 省份数据
var itemStyleD = [
    {   
        name: '湖南',
        itemStyle: {
            normal: {                       
                areaColor: '#0554E4'
            },
            emphasis: {
                areaColor: "#0554E4"
            }                      
        }        
    },
    {   
        name: '上海',
        itemStyle: {
            normal: {                       
                areaColor: '#27E9FD'
            },
            emphasis: {
                areaColor: "#27E9FD"
            }                      
        }        
    },
    {   
        name: '云南',
        itemStyle: {
            normal: {                       
                areaColor: '#20CAF8'
            },
            emphasis: {
                areaColor: "#20CAF8"
            }                      
        }        
    },
    {   
        name: '湖北',
        itemStyle: {
            normal: {                       
                areaColor: '#005ce5'
            },
            emphasis: {
                areaColor: "#005ce5"
            }                      
        }        
    },
    {   
        name: '江苏',
        itemStyle: {
            normal: {                       
                areaColor: '#00b6f6'
            },
            emphasis: {
                areaColor: "#00b6f6"
            }                      
        }        
    },
    {   
        name: '江西',
        itemStyle: {
            normal: {                       
                areaColor: '#01a4f1'
            },
            emphasis: {
                areaColor: "#01a4f1"
            }                      
        }        
    },
    {   
        name: '内蒙古',
        itemStyle: {
            normal: {                       
                areaColor: '#00ccf7'
            },
            emphasis: {
                areaColor: "#00ccf7"
            }                      
        }
    },
    {   
        name: '四川',
        itemStyle: {
            normal: {                       
                areaColor: '#0069e8'
            },
            emphasis: {
                areaColor: "#0069e8"
            }                      
        }        
    },
    {   
        name: '浙江',
        itemStyle: {
            normal: {                       
                areaColor: '#00b6f6'
            },
            emphasis: {
                areaColor: "#00b6f6"
            }                      
        }        
    }
]
var noneData = [
    {
        name: '广东',
        itemStyle: {
          normal: {
              areaColor: '#00d9fc'
          },
          emphasis: {
              areaColor: "#00d9fc"
          }
        }
    },{
        name: '南海诸岛',
        itemStyle: {
            normal: {
                areaColor: '#00d9fc'
            },
            emphasis: {
                areaColor: "#00d9fc"
            }
        }
    },
    {
        name: '湖北',
        itemStyle: {
            normal: {
                areaColor: '#00d9fc'
            },
            emphasis: {
                areaColor: "#00d9fc"
            }
        }
    },
    {
        name: '四川',
        itemStyle: {
            normal: {
                areaColor: '#00d9fc'
            },
            emphasis: {
                areaColor: "#00d9fc"
            }
        }
    },
    {
        name: '云南',
        itemStyle: {
            normal: {
                areaColor: '#00d9fc'
            },
            emphasis: {
                areaColor: "#00d9fc"
            }
        }
    },
    {
        name: '湖南',
        itemStyle: {
            normal: {
                areaColor: '#00d9fc'
            },
            emphasis: {
                areaColor: "#00d9fc"
            }
        }
    },
    {
        name: '江苏',
        itemStyle: {
            normal: {
                areaColor: '#00d9fc'
            },
            emphasis: {
                areaColor: "#00d9fc"
            }
        }
    },
    {
        name: '江西',
        itemStyle: {
            normal: {
                areaColor: '#00d9fc'
            },
            emphasis: {
                areaColor: "#00d9fc"
            }
        }
    },
    {
        name: '浙江',
        itemStyle: {
            normal: {
                areaColor: '#00d9fc'
            },
            emphasis: {
                areaColor: "#00d9fc"
            }
        }
    },
    {
        name: '内蒙古',
        itemStyle: {
            normal: {
                areaColor: '#00d9fc'
            },
            emphasis: {
                areaColor: "#00d9fc"
            }
        }
    },
    {
        name: '甘肃',
        itemStyle: {
          normal: {                        
              areaColor: '#0042df'
          },
          emphasis: {
              areaColor: "#0042df"
          }
        }                    
    },
    {
        name: '河北', 

        itemStyle: {
          normal: {                        
              areaColor: '#034DE4'
          },
          emphasis: {
              areaColor: "#034DE4"
          }
        }                                       
    },
    {
        name: '河南', 

        itemStyle: {
          normal: {                        
              areaColor: '#034DE4'
          },
          emphasis: {
              areaColor: "#034DE4"
          }
        }                    
    },
    {
      name: '黑龙江', 

      itemStyle: {
          normal: {                        
              areaColor: '#17A3F1'
          },
          emphasis: {
              areaColor: "#17A3F1"
          }                          
      }
    },
    {
        name: '山东', 

        itemStyle: {
          normal: {                        
              areaColor: '#4BFFFF'
          },
          emphasis: {
              areaColor: "#4BFFFF"                            
          }       
        }
    },
    {
        name: '新疆', 

        itemStyle: {
          normal: {                        
              areaColor: '#17A3F1'
          },
          emphasis: {
              areaColor: "#17A3F1"
          }       
        }
    },    
    {
      name: '宁夏', 
      itemStyle: {
          normal: {                        
              areaColor: '#01b0f3'                            
          },
          emphasis: {
              areaColor: "#01b0f3",
              opacity: 0.2                            
          }       
      },
      label: {
          show: false
      }                                         
    },
    {
      name: '海南', 
      itemStyle: {
          normal: {                        
              areaColor: '#00f0ff'
          },
          emphasis: {
              areaColor: "#00f0ff",
              opacity: 0.2                            
          }
      },
      label: {
          show: false
      }                                         
    },
    {
      name: '台湾',                   
      itemStyle: {
          normal: {                       
              areaColor: '#0067e7'
          },
          emphasis: {
              areaColor: "#0067e7",
              opacity: 0.2
          }
      },
      label: {
          show: false
      }                     
    },
    {
      name: '香港',                   
      itemStyle: {
          normal: {                        
              areaColor: '#00dafa'
          },
          emphasis: {
              areaColor: "#00dafa",
              opacity: 0.2                            
          }
      },
      label: {
          show: false
      }                                                              
    },
    {
      name: '澳门', 
      itemStyle: {
          normal: {                        
              areaColor: '#00dafa'
          },
          emphasis: {
              areaColor: "#00dafa",
              opacity: 0.2                            
          }
      },
      label: {
          show: false
      }                                                              
    },
    {
      name: '北京', 
      itemStyle: {
          normal: {
            areaColor: '#034DE4'                            
          },
          emphasis: {
            areaColor: "#034DE4",
            opacity: 0.2
          }
      },
      label: {
          show: false
      }                      
    },
    {
        name: '天津', 
        itemStyle: {
            normal: {
                areaColor: '#034DE4'                          
            },
            emphasis: {
                areaColor: "#034DE4",
                opacity: 0.2  
            }
        },
       label: {
            show: false
       }                      
    },
    {
        name: '重庆', 
        itemStyle: {
        normal: {                        
            areaColor: '#0E7DEB'
        },
        emphasis: {
            areaColor: "#0E7DEB",
            opacity: 0.2                            
        }         
        },
        label: {
            show: false
        }                                         
    },      
    {
        name: '辽宁', 
        itemStyle: {
            normal: {                        
                areaColor: '#034DE4'                          
            },
            emphasis: {
                areaColor: "#034DE4",
                opacity: 0.2  
            }
        },
        label: {
            show: false
        }                      
    },
    {
        name: '安徽',                    
        itemStyle: {
        normal: {                        
            areaColor: '#27E8FD'
        },
        emphasis: {
            areaColor: "#27E8FD",
            opacity: 0.2                            
        }
        },
        label: {
            show: false
        }                                          
    },      
    {
        name: '广西', 
        itemStyle: {
        normal: {                        
            areaColor: '#0088ec'
        },
        emphasis: {
            areaColor: "#0088ec",
            opacity: 0.2  
        }       
        },
        label: {
            show: false
        }                      
    },      
    {
        name: '山西',                   
        itemStyle: {
        normal: {                        
            areaColor: '#01d0fa'
        },
        emphasis: {
            areaColor: "#01d0fa",
            opacity: 0.2                            
        }
        },
        label: {
            show: false
        }                      
    },
    {
        name: '陕西', 
        itemStyle: {
        normal: {                        
            areaColor: '#01b0f3'
        },
        emphasis: {
            areaColor: "#01b0f3",
            opacity: 0.2                            
        }
        },
        label: {
            show: false
        }                                                                                                                          
    },
    {
        name: '吉林',                    
        itemStyle: {
        normal: {                        
            areaColor: '#0051e1'                           
        },
        emphasis: {
            areaColor: "#0051e1",
            opacity: 0.2 
        }
        },
        label: {
            show: false
        }                                                            
    },
    {
        name: '福建', 
        itemStyle: {
            normal: {                       
            areaColor: '#0158e3'
        },
        emphasis: {
            areaColor: "#0158e3",
            opacity: 0.2                            
        }
        },
        label: {
            show: false
        }                                        
    },
    {
        name: '贵州', 
        itemStyle: {
        normal: {                        
            areaColor: '#0199ef'                          
        },
        emphasis: {
            areaColor: "#0199ef",
            opacity: 0.2  
        }
        },
        label: {
            show: false
        }                                       
    },      
    {
        name: '青海',                   
        itemStyle: {
            normal: {                        
                areaColor: '#005ae4'                           
            },
            emphasis: {
                areaColor: "#005ae4",
                opacity: 0.2 
            }
        },
        label: {
            show: false
        }                                                             
    },
    {
        name: '西藏',                    
        itemStyle: {
            normal: {                        
            areaColor: '#01e9fd'                           
            },
            emphasis: {
            areaColor: "#01e9fd",
            opacity: 0.2                            
            }       
        },
        label: {
            show: false
        } 
    }
  ]



//lxxing
var findDataMaP="findDataMaP";
var findDataMaPUrl = base +findDataMaP;
var mapData = {Jan: [], Feb: [], Mar: [], Apr: [], May: [], Jun: [], Jul: [], Aug: [], Sep: [], Oct: [], Nov: [], Dec: []};
findMapData()
function findMapData(){
    $.ajax({
        url:findDataMaPUrl,
        type:"POST",
        datatype:"json",
        success:function (result){
            for (let i = 0;i<result.data.length;i++) {
                let data =  result.data[i]
                switch (data.date.substr(4,4)){
                    case "-01-":
                        mapData.Jan.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-02-":
                        mapData.Feb.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-03-":
                        mapData.Mar.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-04-":
                        mapData.Apr.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-05-":
                        mapData.May.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-06-":
                        mapData.Jun.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-07-":
                        mapData.Jul.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-08-":
                        mapData.Aug.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-09-":
                        mapData.Sep.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-10-":
                        mapData.Oct.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-11-":
                        mapData.Nov.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                    case "-12-":
                        mapData.Dec.push({'name':data.name,'uploadcnt':data.uploadcnt,'uploadpzs':data.uploadpzs,'xsmy':data.xsmy,'kcmy':data.kcmy});
                        break;
                }
            }
            concatMapData()
        }
    })
}
function concatMapData(){
    for(key in mapData){
        for(var i = 0; i < mapData[key].length; i++){
            if(
                mapData[key][i]["uploadcnt"].trim() === "" &&
                mapData[key][i]["uploadcnt"].trim() === null &&
                mapData[key][i]["uploadpzs"].trim() === "" &&
                mapData[key][i]["uploadpzs"].trim() === null &&
                mapData[key][i]["xsmy"].trim() === "" &&
                mapData[key][i]["xsmy"].trim() === null &&
                mapData[key][i]["kcmy"].trim() === ""&&
                mapData[key][i]["kcmy"].trim() === null
            ){
                mapData[key][i].label = {show: false}
            }
            for(var j = 0; j < itemStyleD.length; j++){
                if(mapData[key][i]["name"] == itemStyleD[j]["name"]){
                    mapData[key][i].itemStyle = itemStyleD[j]["itemStyle"];
                }
            }
        }
        mapData[key] = mapData[key].concat(noneData)
    }
}
function formatterShow (params){
    var data = params.data;
    var numArr = [];
    var numData = [];
    var formatterStr = '';
    var paramsData =  [
        //     '{a|' + params.name + '}' + '\n',
        "上传条数：" + data.uploadcnt + '条',
        "品种数量：" + data.uploadpzs + '种',
        "销售码洋：" + data.xsmy + '万元',
        "库存码洋：" + data.kcmy + '万元'
    ]

    if(data.uploadcnt != undefined && data.uploadcnt != ''){
        numArr.push(0)
    }
    if(data.uploadpzs != undefined && data.uploadpzs != ''){
        numArr.push(1)
    }
    if(data.xsmy != undefined && data.xsmy != ''){
        numArr.push(2)
    }
    if(data.kcmy != undefined && data.kcmy != ''){
        numArr.push(3)
    }
    for(var i = 0; i < numArr.length; i++){

        numData.push(paramsData[numArr[i]])
    }
    // console.log(numData.join(""))
    if(numData.length == 1){
        formatterStr = '{a|' + params.name + '}' + '\n' + 
                       '{b|' + numData[0] + '}'
    }else if(numData.length == 2){
        formatterStr = '{a|' + params.name + '}' + '\n' + 
                       '{b|' + numData[0] + '}' + '\n' +
                       '{c|' + numData[1] + '}'
    }else if(numData.length == 3){
        formatterStr = '{a|' + params.name + '}' + '\n' + 
                       '{b|' + numData[0] + '}' + '\n' +
                       '{c|' + numData[1] + '}' + '\n' +
                       '{d|' + numData[2] + '}' + '\n'
    }else if(numData.length == 4){
        formatterStr = '{a|' + params.name + '}' + '\n' + 
                       '{b|' + numData[0] + '}' + '\n' +
                       '{c|' + numData[1] + '}' + '\n' +
                       '{d|' + numData[2] + '}' + '\n' +
                       '{e|' + numData[3] + '}' + '\n'
    }

    return formatterStr
}


// 有数据省份
var hasData = [8,9,8,8,8,6,7,7,8,8,8,7];
// 全国12个月数据

var point = 'image://img/point.png';
var curIndx = 0;

var rich = {
  a: {
      color: '#fff',
      fontSize: 18,
      align: 'left',
      padding: [0,0,64,44]
  },
  b: {
      color: '#fff',
      fontSize: 14,        
      padding: [0,0,-60,110],
      align: 'left'
  },
  c: {
      color: '#fff',
      fontSize: 14,       
      padding: [0,0,-25,110],
      align: 'left'

  },
  d: {
      color: '#fff',
      fontSize: 14,        
      padding: [0,0,-2,110],
      align: 'left'
  },
  e: {
      color: '#fff',
      fontSize: 14,       
      padding: [3,0,3,110],
      align: 'left'

  }
}
var option = {
  geo: {
    map: "china",
    label: {
      emphasis: {
        show: true
      }
    },
    roam: false,
    layoutCenter: ["50%", "55%"],
    layoutSize: "110%",
    regions: [
        {
            name: '南海诸岛',
            itemStyle: {
                areaColor: '#6F798D',
                opacity: 0.5
            }
        },
        {
            name: '北京', 
            itemStyle: {
                areaColor: '#034DE4',
                opacity: 0.2                            
            }
        },
        {
            name: '天津', 
            itemStyle: {
							areaColor: '#034DE4',
							opacity: 0.2                            
						}
        },
        {
            name: '上海', 
            itemStyle: {
							areaColor: '#27E9FD',
							opacity: 0.2                            
						}						
						
        },
        {
            name: '重庆', 
            itemStyle: {
							areaColor: '#0E7DEB',
							opacity: 0.2                            
						}                  
        },
        {
            name: '河北', 
						itemStyle: {
							areaColor: '#034DE4',
							opacity: 0.2                            
						}                                      
        },
        {
            name: '河南', 
            itemStyle: {
							areaColor: '#034DE4',
							opacity: 0.2                            
						}
        },
        {
            name: '云南', 
            itemStyle: {
							areaColor: '#20CAF8',
							opacity: 0.2                            
						}
        },
        {
					name: '辽宁', 
					itemStyle: {
						areaColor: '#034DE4',
						opacity: 0.2                            
					}                    
        },
        {
					name: '黑龙江', 
					itemStyle: {
						areaColor: '#17A3F1',
						opacity: 0.2                            
					}
        },
        {
					name: '湖南', 
					itemStyle: {
						areaColor: '#0554E4',
						opacity: 0.2                            
					}
        },
        {
            name: '安徽', 
            itemStyle: {
							areaColor: '#27E8FD',
							opacity: 0.2                            
						}                  
        },
        {
            name: '山东', 
            itemStyle: {
							areaColor: '#4BFFFF',
							opacity: 0.2                            
						}
        },
        {
            name: '新疆', 
						itemStyle: {
							areaColor: '#17A3F1',
							opacity: 0.2                            
						}
        },
        {
            name: '江苏', 
            itemStyle: {
							areaColor: '#00b6f6',
							opacity: 0.2                            
						}                  
        },
        {
            name: '浙江', 
            itemStyle: {
							areaColor: '#00b6f6',
							opacity: 0.2                            
						}                    
        },
        {
            name: '江西', 
            itemStyle: {
							areaColor: '#01a4f1',
							opacity: 0.2                            
						} 
        },
        {
            name: '湖北', 
            itemStyle: {
							areaColor: '#005ce5',
							opacity: 0.2                            
						} 
        },
        {
            name: '广西', 
            itemStyle: {
							areaColor: '#0088ec',
							opacity: 0.2                            
						} 
        },
        {
            name: '甘肃', 
            itemStyle: {
							areaColor: '#0042df',
							opacity: 0.2                            
						}                                       
        },
        {
            name: '山西', 
            itemStyle: {
							areaColor: '#01d0fa',
							opacity: 0.2                            
						}                     
        },
        {
            name: '内蒙古', 
            itemStyle: {
                areaColor: '#00ccf7',
                opacity: 0.2                            
            }                                       
        },
        {
            name: '陕西', 
            itemStyle: {
							areaColor: '#01b0f3',
							opacity: 0.2                            
						} 
        },
        {
            name: '吉林', 
            itemStyle: {
							areaColor: '#0051e1',
							opacity: 0.2                            
						}                                       
        },
        {
            name: '福建', 
            itemStyle: {
							areaColor: '#0158e3',
							opacity: 0.2                            
						} 
        },
        {
            name: '贵州', 
            itemStyle: {
							areaColor: '#0199ef',
							opacity: 0.2                            
						}                    
        },
        {
            name: '广东', 
            itemStyle: {
							areaColor: '#00d9fc',
							opacity: 0.2                            
						} 
        },
        {
            name: '青海', 
            itemStyle: {
							areaColor: '#005ae4',
							opacity: 0.2                            
						} 
        },
        {
            name: '西藏', 
            itemStyle: {
							areaColor: '#01e9fd',
							opacity: 0.2                            
						}                    
        },
        {
					name: '四川', 
					itemStyle: {
						areaColor: '#0069e8',
						opacity: 0.2                            
					} 
        },
        {
					name: '宁夏', 
					itemStyle: {
						areaColor: '#01b0f3',
						opacity: 0.2                            
					}                    
        },
        {
					name: '海南', 
					itemStyle: {
						areaColor: '#00f0ff',
						opacity: 0.2                            
					}                   
        },
        {
					name: '台湾', 
					itemStyle: {
						areaColor: '#0067e7',
						opacity: 0.2                            
					}                                      
        },
        {
					name: '香港', 
					itemStyle: {
						areaColor: '#00dafa',
						opacity: 0.2                            
					} 
        },
        {
					name: '澳门', 
					itemStyle: {
						areaColor: '#00dafa',
						opacity: 0.2                            
					} 
        } 
]
  },
  series: [
    {
      name: "中国",
      type: "map",
      mapType: "china",
      layoutCenter: ["50%", "55%"],
      layoutSize: "110%",
      label: {
        width: 340,
        height: 140,     
        backgroundColor: {
            image: "img/tip-bg.png"
        },
        emphasis: {               
            show:true,
            color: "#fff",    
            formatter: function(params){
                var tt = formatterShow(params)
                return tt;
            }
        },
        rich: rich
      },
      itemStyle: {
        normal: {
            opacity: 0.2
        },
        emphasis: {
            opacity: 1,
            borderWidth: 2,
            borderColor: '#fff'
        }
      },
      data: [
        {
          name: '北京', 
          itemStyle: {
            normal: {
                areaColor: '#034DE4'                            
            },
            emphasis: {
            areaColor: '#034DE4',                            
            opacity: 0.2  
            }
          },
          label: {
              show: false
          }
        },
        {
            name: '天津', 
            itemStyle: {
                normal: {
                    areaColor: '#034DE4'                            
                },
                emphasis: {
                  areaColor: '#034DE4',                            
                  opacity: 0.2  
                }
            },
            label: {
                show: false
            }
        },
        {
            name: '上海', 
            itemStyle: {
                normal: {
                    areaColor: '#27E9FD'   
                },
                emphasis: {
                    areaColor: '#27E9FD'
                }
            },
            label: {
                show: false
            }
        },
        {
            name: '重庆', 
            itemStyle: {
                normal: {                        
                    areaColor: '#0E7DEB'
                },
                emphasis: {
                    areaColor: '#0E7DEB',
                    opacity: 0.2                  
                }
            },
            label: {
                show: false
            }                   
        },
        {
            name: '河北',                    
            itemStyle: {
                normal: {                        
                    areaColor: '#034DE4'
                },
                emphasis: {
                    areaColor: '#034DE4'
                }
            }                                       
        },
        {
            name: '河南',                    
            itemStyle: {
                normal: {                        
                    areaColor: '#034DE4'
                },
                emphasis: {
                    areaColor: '#034DE4'
                }
            }
        },
        {
            name: '云南', 
            itemStyle: {
                normal: {                        
                    areaColor: '#20CAF8'
                },
                emphasis: {
                    areaColor: '#20CAF8'
                }
            },
            label: {
                show: false
            }
        },
        {
            name: '辽宁', 
            itemStyle: {
                normal: {                        
                    areaColor: '#034DE4'
                },
                emphasis: {
                    areaColor: '#034DE4',
                    opacity: 0.2
                }
            },
            label: {
                show: false
            }                     
        },
        {
            name: '黑龙江', 
            itemStyle: {
                normal: {                        
                    areaColor: '#17A3F1'
                },
                emphasis: {
                    areaColor: "#17A3F1"
                }                          
            }
        },
        {
            name: '湖南', 
            itemStyle: {
                normal: {                       
                    areaColor: '#0554E4'                      
                },
                emphasis: {
                    areaColor: '#0554E4'                      
                }      
            } 
        },
        {
            name: '安徽', 
            itemStyle: {
                normal: {                        
                    areaColor: '#27E8FD'
                },
                emphasis: {
                    areaColor: '#27E8FD',
                    opacity: 0.2                      
                }      
            },
            label: {
                show: false
            }                    
        },
        {
            name: '山东', 
            itemStyle: {
                normal: {                        
                    areaColor: '#4BFFFF'                    
                },
                emphasis: {
                    areaColor: '#4BFFFF'
                }       
            }
        },
        {
            name: '新疆', 
            itemStyle: {
                normal: {                        
                    areaColor: '#17A3F1'    
                },
                emphasis: {
                    areaColor: '#17A3F1'                       
                }       
            }
        },
        {
            name: '江苏', 
            itemStyle: {
                normal: {                        
                    areaColor: '#00b6f6'
                },
                emphasis: {
                    areaColor: '#00b6f6'
                }
            }                   
        },
        {
            name: '浙江', 
            itemStyle: {
                normal: {                        
                    areaColor: '#00b6f6'
                },
                emphasis: {
                    areaColor: '#00b6f6',
                    opacity: 0.2
                }
            },
            label: {
                show: false
            }                    
        },
        {
            name: '江西', 
            itemStyle: {
                normal: {                        
                    areaColor: '#01a4f1'
                },
                emphasis: {
                    areaColor: '#01a4f1'
                }
            }                                        
        },
        {
            name: '湖北', 
            itemStyle: {
                normal: {                        
                    areaColor: '#005ce5'
                },
                emphasis: {
                    areaColor: '#005ce5'
                }
            }                                                            
        },
        {
            name: '广西', 
            itemStyle: {
                normal: {                        
                    areaColor: '#0088ec'                           
                },
                emphasis: {
                    areaColor: '#0088ec',
                    opacity: 0.2
                }
            },
            label: {
                show: false
            }                    
        },
        {
            name: '甘肃', 
            itemStyle: {
                normal: {                        
                    areaColor: '#0042df'
                },
                emphasis: {
                    areaColor: '#0042df'
                }
            }                    
        },
        {
            name: '山西', 
            itemStyle: {
                normal: {                        
                    areaColor: '#01d0fa'
                },
                emphasis: {
                    areaColor: '#01d0fa',
                    opacity: 0.2
                }
            },
            label: {
                show: false
            } 
        },
        {
            name: '内蒙古',
            itemStyle: {
                normal: {
                    areaColor: '#00ccf7'
                },
                emphasis: {
                    areaColor: '#00ccf7'
                }
            },
            label: {
                show: false
            }
        },
        {
            name: '陕西', 
            itemStyle: {
                normal: {                        
                    areaColor: '#01b0f3'
                },
                emphasis: {
                    areaColor: '#01b0f3',
                    opacity: 0.2
                }
            },
            label: {
                show: false
            }                                                              
        },
        {
            name: '吉林', 
            itemStyle: {
                normal: {                        
                    areaColor: '#0051e1'
                },
                emphasis: {
                    areaColor: '#0051e1',
                    opacity: 0.2
                }
            },
            label: {
                show: false
            }                                                                                
        },
        {
            name: '福建', 
            itemStyle: {
                normal: {                       
                    areaColor: '#0158e3'
                },
                emphasis: {
                    areaColor: '#0158e3',
                    opacity: 0.2
                }
            },
            label: {
                show: false
            }                                                                                                      
        },
        {
            name: '贵州', 
            itemStyle: {
                normal: {                        
                    areaColor: '#0199ef'
                },
                emphasis: {
                    areaColor: '#0199ef',
                    opacity: 0.2
                }
            },
            label: {
                show: false
            }                                                                                                                                            
        },
        {
          name: '广东', 
          itemStyle: {
              normal: {                        
                  areaColor: '#00d9fc'                            
              },
              emphasis: {
                  areaColor: '#00d9fc',
                  opacity: 0.2
              }
          },
          label: {
              show: false
          }                                                                                                      
        },
        {
            name: '青海', 
            itemStyle: {
                normal: {                        
                    areaColor: '#005ae4'
                },
                emphasis: {
                    areaColor: '#005ae4',
                    opacity: 0.2                    
                }
            },
            label: {
                show: false
            }                    
        },
        {
            name: '西藏', 
            itemStyle: {
                normal: {                        
                    areaColor: '#01e9fd'                            
                },
                emphasis: {
                    areaColor: '#01e9fd',
                    opacity: 0.2                    
                }
            },
            label: {
                show: false
            }
        },
        {
            name: '四川', 
            itemStyle: {
                normal: {                        
                    areaColor: '#0069e8'                           
                },
                emphasis: {
                    areaColor: '#0069e8'
                }
            },
            label: {
                show: false
            }
        },
        {
            name: '宁夏', 
            itemStyle: {
                normal: {                        
                    areaColor: '#01b0f3'                            
                },
                emphasis: {
                    areaColor: '#01b0f3',
                    opacity: 0.2                    
                }
            },
            label: {
                show: false
            }
        },
        {
            name: '海南', 
            itemStyle: {
                normal: {                        
                    areaColor: '#00f0ff'
                },
                emphasis: {
                    areaColor: '#00f0ff',
                    opacity: 0.2                    
                }
            },
            label: {
                show: false
            }                    
        },
        {
            name: '台湾',                  
            itemStyle: {
                    normal: {                       
                    areaColor: '#0067e7'
                },
                emphasis: {
                    areaColor: '#0067e7',
                    opacity: 0.2                    
                }
            },
            label: {
                show: false
            }                    
        },
        {
            name: '香港', 
            itemStyle: {
                normal: {                        
                    areaColor: '#00dafa'
                },
                emphasis: {
                    areaColor: '#00dafa',
                    opacity: 0.2                    
                }
            },
            label: {
                show: false
            }                                         
        },
        {
            name: '澳门', 
            itemStyle: {
                normal: {                        
                    areaColor: '#00dafa'                                                    
                },
                emphasis: {
                    areaColor: '#00dafa',
                    opacity: 0.2                    
                }
            },
            label: {
                show: false
            }
        }        
      ],
    },
    {
      name: "数据集中点",
      type: "scatter",
      coordinateSystem: "geo",
			data: convertData(data),
			symbol: point,
      symbolSize: function(val) {
        return val[2] / 8;
      },
      label: {
        normal: {
          formatter: "{b}",
          position: "right",
          show: false
        },
        emphasis: {
          show: true
        }
      },
      itemStyle: {
        normal: {
          color: "#ffff00"
        }
      }
    }
  ]
};


mapChart.setOption(option);

// 渲染全国四种数据1月份
$('#book-data').text(allMData["book"][0]);
$('#varity-data').text(allMData["variety"][0]);
$('#sales-data').text(allMData["sales"][0]);
$('#stock-data').text(allMData["stock"][0]);
mapChart.currentIndex = -1;

var monthIndex = 0;
var bNum = 0;
var startN = 0;
var timer = null;
setVal();


//   畅销书排行
var ranktUl = $('.aside-left .top ul');
var bookLiLen = ranktUl.eq(0).children().length;
var conH = $('.aside-left .top .con-wrap').height(); 
var bookNum = 0;
var timer01 = null;
var overWrapEle = $('.aside-left .top .con-wrap .over-wrap');

var booktimerFn = function(bNum){
    clearTimeout(timer01);

    timer01 = setInterval(function(){

        bookNum++;
        ranktUl.eq(bNum).children().removeClass('active');
        ranktUl.eq(bNum).children().eq(bookNum).addClass('active');

        if(bookNum == (bookLiLen-1)){
            clearInterval(timer01);
            bookNum = 0;
        }
    },3000);

}
// 监听过渡动画回调函数
var ListenTr = function(bNum){
    // 过渡动画回调，执行定时切换
    var e = overWrapEle[0];

    function whichTransitionEvent(){
    var t,
        el = document.createElement('surface'),
        transitions = {
            'transition':'transitionend',
            'OTransition':'oTransitionEnd',
            'MozTransition':'transitionend',
            'WebkitTransition':'webkitTransitionEnd'
        }

        for(t in transitions){
            if( el.style[t] !== undefined ){
                return transitions[t];
            }
        }
    }

    var transitionEvent = whichTransitionEvent();
    transitionEvent && e.addEventListener(transitionEvent, function() {
        booktimerFn(bNum);
        e. removeEventListener(transitionEvent,arguments.callee,false);//销毁事件

    });
}
var numGoFn = function(monthIndex){
    //   将月份填入
    var curTime = '2017年' + (monthIndex+1) + '月';
    $('.month-tip').text(curTime);
    //   全国数据关联月份
    var newBData,oldBData,newVData,oldVData,newMData,oldMData,newSData,oldSData;

        newBData = allMData["book"][monthIndex];
        oldBData = monthIndex == 0? allMData["book"][11]: allMData["book"][monthIndex -1];
        
        newVData = allMData["variety"][monthIndex];
        oldVData = monthIndex == 0? allMData["variety"][11]: allMData["variety"][monthIndex -1];
        
        newMData = allMData["sales"][monthIndex];
        oldMData = monthIndex == 0? allMData["sales"][11]: allMData["sales"][monthIndex -1];        

        newSData = allMData["stock"][monthIndex];
        oldSData = monthIndex == 0? allMData["stock"][11]: allMData["stock"][monthIndex -1];

    // 数据滚动效果
    var options = {
    useEasing: true,
    useGrouping: true,
    separator: ',',
    decimal: '.',
    };

    var demoB = new CountUp('book-data', oldBData, newBData, 0, 2.5, options);
    if (!demoB.error) {
    demoB.start();
    } else {
    console.error(demoB.error);
    }

    var demoV = new CountUp('varity-data', oldVData, newVData, 0, 2.5, options);
    if (!demoV.error) {
    demoV.start();
    } else {
    console.error(demoV.error);
    }

    var demoM = new CountUp('sales-data', oldMData, newMData, 0, 2.5, options);
    if (!demoM.error) {
    demoM.start();
    } else {
    console.error(demoM.error);
    }

    var demoS = new CountUp('stock-data', oldSData, newSData, 0, 2.5, options);
    if (!demoS.error) {
    demoS.start();
    } else {
    console.error(demoS.error);
    } 
}

//   出版社排行
var pressNum = 0;
var timerNum = null;

var presstimerFn = function(monthIndex){

    clearTimeout(timerNum);

    // // 先灌数据
    // $('.aside-left .bottom .con li').each(function(){
    //     var cur = $(this).index();
    //     var pressTxt = $(this).find('.short').text(pressRanking[Month[monthIndex]][cur]["pressName"]);
    //     var hotTxt = $(this).find('.hot').text(pressRanking[Month[monthIndex]][cur]["hotVal"]);
    //
    // });
    var rankbUl = $('.aside-left .bottom ul');
    var rankbLen = rankbUl.children().length;
    timerNum = setInterval(function(){
        
        var curLi = rankbUl.children().eq(pressNum);
        curLi.children('.book-rank').addClass('pressRotate');
        curLi.siblings().children('.book-rank').removeClass('pressRotate');
        pressNum++;

        if(pressNum > rankbLen){
          pressNum = 0;
          clearTimeout(timerNum);
        }
      },1000);
}
presstimerFn(0);

// 销售码洋排行

var html = '';

var stockRankFn = function(monthIndex){
    var len = saleStockR[Month[monthIndex]].length;
    $('.aside-right .area-rank ul').html('');
    html = '';
    for(var i = 0; i < len; i++){
        var pro = saleStockR[Month[monthIndex]][i]["name"];
        var val = saleStockR[Month[monthIndex]][i]["value"];

        html += '<li>' + 
                    '<span class="num">' + (i+1) + '</span>' +     
                    '<span class="city-name">' + pro + '</span>' +
                    '<span class="bar">' +
                        '<b class="bar-in" style="width: ' + (val / 12) + '%"></b>' +
                    '</span>' +
                    '<span class="rank-value">' + val + '万' + '</span>' +
                '</li>'

    }
    $('.aside-right .area-rank ul').html(html)
}  

stockRankFn(0);

//   // 饼图
var pie1 = echarts.init(document.getElementById('pie1'),'macarons');
var pie2 = echarts.init(document.getElementById('pie2'),'macarons');

var pieRich = {
    big: {
        fontSize: 24,
        lineHeight: 40,
        fontFamily: 'Rubik'
    },
    small: {
        fontSize: 16
    },

}
var pieOption1 = {
  legend: {
      x: 'left',
      data:[],
      top: '68%',
      left: 'center',
      itemWidth: 15,
      itemHeight: 8,
      textStyle: {
          color: '#fff'
      }
  },
  series: [
      {
          name:'销售占比',
          type:'pie',
          radius: ['55%', '65%'],
          hoverOffset: 5,
          center: ['50%','35%'],
          avoidLabelOverlap: false,
          color: ['#0239a7', '#fff', '#00bbec', '#23539b', '#24feb4','#1397ff'],
          label: {
              normal: {
                  show: false,
                  position: 'center'
              }
              ,
              emphasis: {
                  show: true,  
                  color: '#fff',                
                  formatter: function(params, ticket, callback) {
                    // console.log
                      return '{big|' + params.value + '}{small|%}\n{small|' + params.name + '}';
                  },
                  // '{a|这段文本采用样式a}'
                  rich: pieRich
              }
          },
          labelLine: {
              normal: {
                  show: false
              }
          },
          data:[]
      }
  ]
};
var pieOption2 = {
  legend: {
      x: 'left',
      data:[],
      top: '68%',
      left: 'center',
      itemWidth: 15,
      itemHeight: 8,
      textStyle: {
          color: '#fff'
      }
  },
  series: [
      {
          name:'库存占比',
          type:'pie',
          radius: ['55%', '65%'],
          hoverOffset: 5,
          avoidLabelOverlap: false,
          color: ['#0239a7', '#fff', '#00bbec', '#23539b', '#24feb4','#1397ff'],
          center: ['50%','35%'],
          label: {
              normal: {
                  show: false,
                  position: 'center'
              }
              ,
              emphasis: {
                  show: true,  
                  color: '#fff',                
                  formatter: function(params, ticket, callback) {

                      return '{big|' + params.value + '}{small|%}\n{small|' + params.name + '}';
                  },
                  // '{a|这段文本采用样式a}'
                  rich: pieRich
              }
          },
          labelLine: {
              normal: {
                  show: false
              }
          },
          data:[]
      }
  ]
};
pie1.currentIndex = -1;
pie1.setOption(pieOption1);
setInterval(function () {
    var dataLen = pieOption1.series[0].data.length;
    // 取消之前高亮的图形
    pie1.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
        dataIndex: pie1.currentIndex
    });
    pie1.currentIndex = (pie1.currentIndex + 1) % dataLen;
    // 高亮当前图形
    pie1.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: pie1.currentIndex
    });
}, 1000);
pie2.currentIndex = -1;
pie2.setOption(pieOption2);
setInterval(function () {
    var dataLen = pieOption2.series[0].data.length;
    // 取消之前高亮的图形
    pie2.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
        dataIndex: pie2.currentIndex
    });
    pie2.currentIndex = (pie2.currentIndex + 1) % dataLen;
    // 高亮当前图形
    pie2.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: pie2.currentIndex
    });
}, 1000);

var pieDataFn = function(){
    /*
    分类销量数量占比渲染
     */
    $.ajax({
        url:SortSellQuantityUrl,
        type:'get',
        datatype:'json',
        success:function (result) {
            // console.log(result);
            // console.log(result.data.quantity)
            var sum = 0;
            for (var i =0;i<result.data.length;i++){
                sum+=parseFloat(result.data[i].quantity);
                // console.log(result.data[i].quantity)
            }
            // console.log(sum);
            var data = [];
            for (var i =0;i<result.data.length;i++){
                data=[
                    {
                        value:(result.data[0].quantity/sum).toFixed(2)*100,
                        name:result.data[0].label_name,
                        label: {
                            normal: {
                                formatter: '{c}%\n\n{b}'
                            }
                        }
                    },
                    {
                        value:(result.data[1].quantity/sum).toFixed(2)*100,
                        name:result.data[1].label_name,
                        label: {
                            normal: {
                                formatter: '{c}%\n\n{b}'
                            }
                        }
                    },
                    {
                        value: (result.data[2].quantity/sum).toFixed(2)*100,
                        name:result.data[2].label_name,
                        label: {
                            normal: {
                                formatter: '{c}%\n\n{b}'
                            }
                        }
                    },
                    {
                        value: (result.data[3].quantity/sum).toFixed(2)*100,
                        name:result.data[3].label_name,
                        label: {
                            normal: {
                                formatter: '{c}%\n\n{b}'
                            }
                        }
                    }
                ];
            }
            for(var i=0; i< data.length; i++ ){
                pieOption1["legend"]["data"].push(data[i]["name"]);
            }
            pieOption1.series[0].data = data;
            pie1.setOption(pieOption1);
        }
    })

    /*
    分类库存数量占比
     */
    $.ajax({
        url:sortStockQuantityUrl,
        type:'get',
        datatype:'json',
        success:function (result) {
            // console.log(result);
            // console.log(result.data.stock)
            var sum = 0;
            for (var i =0;i<result.data.length;i++){
                sum+=parseFloat(result.data[i].stock);
                // console.log(result.data[i].stock)
            }
            // console.log(sum);
            var data = [];
            for (var i =0;i<result.data.length;i++){
                data=[
                    {
                        value:(result.data[0].stock/sum).toFixed(2)*100,
                        name:result.data[0].label_name,
                        label: {
                            normal: {
                                formatter: '{c}%\n\n{b}'
                            }
                        }
                    },
                    {
                        value:(result.data[1].stock/sum).toFixed(2)*100,
                        name:result.data[1].label_name,
                        label: {
                            normal: {
                                formatter: '{c}%\n\n{b}'
                            }
                        }
                    },
                    {
                        value: (result.data[2].stock/sum).toFixed(2)*100,
                        name:result.data[2].label_name,
                        label: {
                            normal: {
                                formatter: '{c}%\n\n{b}'
                            }
                        }
                    },
                    {
                        value: (result.data[3].stock/sum).toFixed(2)*100,
                        name:result.data[3].label_name,
                        label: {
                            normal: {
                                formatter: '{c}%\n\n{b}'
                            }
                        }
                    }
                ];
            }
            for(var i=0; i< data.length; i++ ){
                pieOption2["legend"]["data"].push(data[i]["name"]);
            }
            pieOption2.series[0].data = data;
            pie2.setOption(pieOption2);
        }
    })


    // for(var i=0; i< data.length; i++ ){
    //   pieOption1["legend"]["data"].push(data[i]["name"]);
      // pieOption2["legend"]["data"].push(curD2[i]["name"]);
    // }
    // pieOption1.series[0].data = data;
    // pieOption2.series[0].data = curD2;
    // pie1.setOption(pieOption1);
    // pie2.setOption(pieOption2);
}


pieDataFn(0);
function setVal() {
  clearTimeout(timer);

  timer = setInterval(function() {
    
    if (mapChart.currentIndex == -1 && monthIndex == 0) {
        
      option.series[0].data = mapData[Month[0]];


      mapChart.setOption(option);
    }

    var dataLen = mapData["Jan"].length;
    // 取消之前高亮的图形
    mapChart.dispatchAction({
      type: "downplay",
      seriesIndex: 0,
      dataIndex: mapChart.currentIndex
    });
    mapChart.currentIndex = (mapChart.currentIndex + 1) % dataLen;
    // 高亮当前图形
    mapChart.dispatchAction({
      type: "highlight",
      seriesIndex: 0,
      dataIndex: mapChart.currentIndex
    });


    if (mapChart.currentIndex === hasData[monthIndex]) {
        mapChart.currentIndex = -1;
        monthIndex++;
        
        if(monthIndex > 11){
            monthIndex = monthIndex%12;
        }

        option.series[0].data = mapData[Month[monthIndex]];

        mapChart.setOption(option);

        
    }
    
  }, 2000);
}

// var chinaEchartsObj = echarts.getMap('china');
// var geoJSONChina = chinaEchartsObj.geoJson;
// var allDefProvince = geoJSONChina.features;
//
// for(var i = 0, len = allDefProvince.length; i < len; i++){
//    var sglProvinceProperties = allDefProvince[i].properties;
//    var sglProvinceName = sglProvinceProperties.name;
//    switch(sglProvinceName){
//         case '湖北':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '湖南':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '江西':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '甘肃':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '新疆':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '上海':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '江苏':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '云南':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '广东':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '浙江':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '河北':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '山东':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '河南':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '四川':
//             sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//         case '内蒙古':
//  sglProvinceProperties.cp[0] = 128.642464;
// 			sglProvinceProperties.cp[1] = 34.756967;
//             break;
//     }
// }
